home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / hole.cls < prev    next >
Encoding:
Visual Basic class definition  |  2004-03-05  |  37.2 KB  |  1,074 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "Detail"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Option Explicit
  15. '/******************************************************************/
  16. '/*                                                                */
  17. '/*                      TurboCAD for Windows                      */
  18. '/*                   Copyright (c) 1993 - 2001                    */
  19. '/*             International Microcomputer Software, Inc.         */
  20. '/*                            (IMSI)                              */
  21. '/*                      All rights reserved.                      */
  22. '/*                                                                */
  23. '/******************************************************************/
  24.  
  25. 'DBAPI constants
  26. Const gkGraphic = 11
  27. Const gkArc = 2
  28. Const gkText = 6
  29. Const gfCosmetic = 128&
  30.                                                                                                                                                                                              
  31. 'Useful math constants
  32. Const Pi# = 3.14159265
  33.  
  34. 'Real variant types!
  35. Const typeEmpty = 0
  36. Const typeInteger = 2
  37. Const typeLong = 3
  38. Const typeSingle = 4
  39. Const typeDouble = 5
  40. Const typeCurrency = 6
  41. Const typeDate = 7
  42. Const typeString = 8
  43. Const typeObject = 9
  44. Const typeBoolean = 11
  45. Const typeVariant = 12
  46. Const typeIntegerEnum = typeInteger + 100
  47. Const typeLongEnum = typeLong + 100
  48. Const typeStringEnum = typeString + 100
  49.  
  50. 'Stock property pages
  51. Const ppStockPen = 1
  52. Const ppStockBrush = 2
  53. Const ppStockText = 4
  54. Const ppStockInsert = 8
  55. Const ppStockViewport = 16
  56. Const ppStockAuto = 32
  57.  
  58. 'Property Ids
  59. Const idDiameter = 1
  60. Const idLength = 2
  61. Const idHType = 3
  62. Const idHoleView = 4
  63.  
  64. Const idLengthOld = 5
  65. Const idLengthThread = 6
  66.  
  67. Const idDiameterOld = 7
  68. Const idHTypeOld = 8
  69. Const idHoleViewOld = 9
  70. Const idLengthThreadOld = 10
  71.  
  72. Const idX0Old = 11
  73. Const idY0Old = 12
  74. Const idX1Old = 13
  75. Const idY1Old = 14
  76. Const idX2Old = 15
  77. Const idY2Old = 16
  78.  
  79.  
  80. 'Property enums
  81. Const NUM_TYPES = 0
  82.  
  83.  
  84. 'Number of properties, pages, wizards
  85. Const NUM_PROPERTIES = 16
  86. Const NUM_PAGES = 1
  87. Const NUM_WIZARDS = 0
  88.  
  89. Private PColor As Long
  90. Private BColor As Long
  91.  
  92. Private Sub Class_Initialize()
  93.     'Initialize class variables
  94. End Sub
  95.  
  96. 'Returns the user-visible description of this RegenMethod
  97. Public Property Get Description() As String
  98.     Description = "Holes"
  99. End Property
  100.  
  101. 'Returns the persistent class id for this RegenMethod's property section
  102. Public Property Get ClassID() As String
  103.     ClassID = "{FDB6F1C3-9631-11d1-A40A-0000B465872B}"
  104. End Property
  105.  
  106. 'Retrieve types and names
  107. Public Function GetPropertyInfo(Names As Variant, Types As Variant, _
  108.     IDs As Variant, Defaults As Variant) As Long
  109.     ReDim Names(NUM_PROPERTIES), Types(NUM_PROPERTIES), _
  110.         IDs(NUM_PROPERTIES), Defaults(NUM_PROPERTIES)
  111.         
  112.     Names(0) = "DiameterH"
  113.     Types(0) = typeDouble
  114.     IDs(0) = idDiameter
  115.     Defaults(0) = 1#
  116.  
  117.     Names(1) = "LengthH"
  118.     Types(1) = typeDouble
  119.     IDs(1) = idLength
  120.     Defaults(1) = 3#
  121.     
  122.     Names(2) = "HType"
  123.     Types(2) = typeString
  124.     IDs(2) = idHType
  125.     Defaults(2) = "Hole1"
  126.     
  127.     Names(3) = "HoleView"
  128.     Types(3) = typeString
  129.     IDs(3) = idHoleView
  130.     Defaults(3) = "FrontSection"
  131.     
  132.     Names(4) = "LengthOldH"
  133.     Types(4) = typeDouble
  134.     IDs(4) = idLengthOld
  135.     Defaults(4) = 3#
  136.    
  137.     Names(5) = "LengthThreadH"
  138.     Types(5) = typeDouble
  139.     IDs(5) = idLengthThread
  140.     Defaults(5) = 1.5
  141.    
  142.     Names(6) = "DiameterOldH"
  143.     Types(6) = typeDouble
  144.     IDs(6) = idDiameterOld
  145.     Defaults(6) = 1#
  146.     
  147.     Names(7) = "HTypeOld"
  148.     Types(7) = typeString
  149.     IDs(7) = idHTypeOld
  150.     Defaults(7) = "HexBolt"
  151.     
  152.     Names(8) = "HoleViewOld"
  153.     Types(8) = typeString
  154.     IDs(8) = idHoleViewOld
  155.     Defaults(8) = "FrontSection"
  156.     
  157.     Names(9) = "LengthThreadOldH"
  158.     Types(9) = typeDouble
  159.     IDs(9) = idLengthThreadOld
  160.     Defaults(9) = 1.5
  161.     
  162.     Names(10) = "X0OldH"
  163.     Types(10) = typeDouble
  164.     IDs(10) = idX0Old
  165.     Defaults(10) = 0#
  166.    
  167.     Names(11) = "Y0OldH"
  168.     Types(11) = typeDouble
  169.     IDs(11) = idY0Old
  170.     Defaults(11) = 0#
  171.    
  172.     Names(12) = "X1OldH"
  173.     Types(12) = typeDouble
  174.     IDs(12) = idX1Old
  175.     Defaults(12) = 3#
  176.    
  177.     Names(13) = "Y1OldH"
  178.     Types(13) = typeDouble
  179.     IDs(13) = idY1Old
  180.     Defaults(13) = 0#
  181.    
  182.     Names(14) = "X2OldH"
  183.     Types(14) = typeDouble
  184.     IDs(14) = idX2Old
  185.     Defaults(14) = 1.5
  186.    
  187.     Names(15) = "Y2OldH"
  188.     Types(15) = typeDouble
  189.     IDs(15) = idY2Old
  190.     Defaults(15) = 0#
  191.     
  192.    GetPropertyInfo = NUM_PROPERTIES
  193. End Function
  194.  
  195. 'Get the number of property pages supporting this RegenMethod
  196. Public Function GetPageInfo(ByVal AGraphic As Object, StockPages As Long, _
  197.     Names As Variant) As Long
  198.     ReDim Names(NUM_PAGES)
  199.  
  200.     'Need the form
  201. ''    Load frmHole
  202. ''    Names(0) = frmHole.Caption
  203. ''    Unload frmHole
  204.     Names(0) = LoadResString(101)
  205.     StockPages = ppStockBrush + ppStockPen + ppStockAuto
  206.     GetPageInfo = NUM_PAGES
  207. End Function
  208.  
  209. Public Function GetWizardInfo(Names As Variant) As Long
  210.     ReDim Names(NUM_WIZARDS)
  211.     GetWizardInfo = NUM_WIZARDS
  212. End Function
  213.  
  214. 'Enumerate the names and values of a specified property
  215. Public Function GetEnumNames(ByVal PropID As Long, Names As Variant, Values As Variant) As Long
  216.         GetEnumNames = 0
  217. End Function
  218.  
  219. Public Function PageControls(ByVal ThisRegenMethod As Object, ByVal Graphic As Object, ByVal PageNumber As Long, ByVal SaveProperties As Boolean) As Boolean
  220.         'Set up error function
  221.         On Error GoTo Failed
  222.         Dim Diameter#, Length#, LengthThread#
  223.         If SaveProperties Then
  224.             'OK button on property page was clicked
  225.             'Form is still loaded
  226.             With frmHole
  227.                 'Need On Error statement for the case where you have
  228.                 'RRect Turbo Shape and ahother "shape" selected
  229.                 On Error Resume Next
  230.                 'When the property page is closed, transfer the numeric
  231.                 'Diameter value from the TextBox to the Graphic
  232.                 'Get the value as a double-precision number
  233.                 Diameter# = CDbl(.txtdd.Text)
  234.                 Length# = CDbl(.txtLen.Text)
  235.                 LengthThread# = CDbl(.txtThread.Text)
  236.                 TypeH = .List1.Text
  237. '                ViewH = .List2.Text
  238.                 'Make sure it's between 0 and 100
  239.                 If Diameter# < 0# Then Diameter# = 1#
  240.                 If Diameter# > 3# Then Diameter# = 3#
  241.                 If LengthThread > Length Then LengthThread = Length
  242.                 'Set the roundness property value in the Graphic
  243.                 Graphic.Properties("DiameterH") = Diameter#
  244.                 Graphic.Properties("LengthH") = Length#
  245.                 Graphic.Properties("LengthThreadH") = LengthThread#
  246.                 Graphic.Properties("HType") = TypeH
  247.             End With
  248.         Else
  249.             'Property page is about to be opened
  250.             'Make sure the form is loaded
  251.                 Diameter# = Graphic.Properties("DiameterH")
  252.                 Length# = Graphic.Properties("LengthH")
  253.                 LengthThread = Graphic.Properties("LengthThreadH")
  254.                 TypeH = Graphic.Properties("HType")
  255.             Load frmHole
  256.             With frmHole
  257.             
  258.                 'If more than one RRect is selected and they do not
  259.                 'have the same properties, don't set up this field
  260.                 On Error GoTo NoRType
  261.  
  262.                 'When the property page is opening, transfer the numeric
  263.                 'Set the TextBox control's text
  264.                 .txtdd.Text = Diameter#
  265.                 .txtLen = Length#
  266.                 .txtThread.Text = LengthThread#
  267. NoRType:
  268.             End With
  269.         End If
  270.  
  271.         PageControls = True
  272.         Exit Function
  273.  
  274. Failed:
  275.         'For debugging purposes, report that an error occurred
  276.         If Err.Number <> 0 Then
  277.             MsgBox "Error in PageControls: " & Err.Description
  278.         End If
  279.  
  280.         'Return false if an error occurred
  281.         PageControls = False
  282. End Function
  283.  
  284. Public Function PageDone(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant)
  285.         'Done with form
  286.         Unload frmHole
  287. End Function
  288.  
  289. Public Function PropertyPages(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant) As Boolean
  290.     With frmHole
  291.         .Show vbModal
  292.         PropertyPages = Not .DialogCanceled
  293.     End With
  294. End Function
  295.  
  296. Public Function Wizard(ByVal ThisRegenMethod As Object, Optional WizardNumber As Variant) As Boolean
  297.     Wizard = False
  298. End Function
  299.  
  300. 'Called when vertex has been moved, or other geometry change
  301. Public Function OnGeometryChanged(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant)
  302.     'Do nothing
  303.     'Regen Graphic
  304. End Function
  305.  
  306. 'Called when vertex is moved, or other geometry change
  307. Public Function OnGeometryChanging(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant) As Boolean
  308.     'OK to continue with change
  309.     OnGeometryChanging = True
  310. End Function
  311.  
  312. Public Function OnNewGraphic(ByVal grfThis1 As Object, ByVal boolCopy As Boolean) As Boolean
  313.     If boolCopy Then
  314.         'Vertices are already added for us...
  315.         OnNewGraphic = True
  316.         Exit Function
  317.     End If
  318. Dim grfThis As Graphic
  319.     Set grfThis = grfThis1
  320.     On Error GoTo Failed
  321.     'New Graphic being created
  322.     'X, Y, Z, PenDown, Selectable, Snappable, Editable, Linkable
  323.     'First Vertex is "first point of axis"
  324.     grfThis.Vertices.Add 0#, 0, 0#, False, True, True, True, True, False
  325.     
  326.     'Second Vertex is "Second point of axis"
  327.     grfThis.Vertices.Add 3#, 0, 0#, False, True, True, True, True, False
  328.     
  329.     'Third Vertex is "Point on theard"
  330.     grfThis.Vertices.Add 1.5, 0, 0#, False, True, True, True, True, False
  331.      
  332.     grfThis.Properties("PenColor") = RGB(0, 0, 0)
  333.     grfThis.Properties("BrushColor") = RGB(255, 255, 255)
  334.     OnNewGraphic = True
  335.     Exit Function
  336.  
  337. Failed:
  338.     'Return false on failure
  339.     OnNewGraphic = False
  340. End Function
  341.  
  342. 'Function called whenever a copy of a graphic is being made
  343. Public Function OnCopyGraphic(ByVal grfCopy As Object, ByVal grfSource As Object) As Boolean
  344.     'Return false on failure
  345.     OnCopyGraphic = True
  346. End Function
  347.  
  348. 'Notification function called after graphic property is saved
  349. Public Function OnPropertyChanged(ByVal Graphic As Object, ByVal PropID As Long, _
  350.         ValueOld As Variant, ValueNew As Variant)
  351.     'Do nothing
  352. End Function
  353.  
  354. 'Notification function called when graphic property is saved
  355. Public Function OnPropertyChanging(ByVal Graphic As Object, ByVal PropID As Long, _
  356.         ValueOld As Variant, ValueNew As Variant) As Boolean
  357.     'OK to proceed
  358.     OnPropertyChanging = True
  359. End Function
  360.  
  361. 'Notification function called when graphic property is retrieved
  362. Public Function OnPropertyGet(ByVal Graphic As Object, ByVal PropID As Long)
  363.     'Do nothing
  364. End Function
  365.  
  366. 'Called when we need to update our object
  367. Public Function Regen(ByVal grfThis1 As Object)
  368.         'Setup error handler
  369.         On Error GoTo Failed
  370. Dim grfThis As Graphic
  371.         Set grfThis = grfThis1
  372.         'Set up lock (prevent recursion)
  373.  
  374. Dim LockCount&
  375.         LockCount& = grfThis.RegenLock
  376.  
  377.         PColor = grfThis.Properties("PenColor")
  378. ''AALB problem with load old files
  379. ' AALB try to fix bug with reading files from TC v6.5 (problem is that some sdk regens
  380. ' has Type = 7(Group, must be GRAPHIc (11))
  381. On Error Resume Next
  382. Err.Clear
  383.         BColor = grfThis.Properties("BrushColor")
  384.         If Err.Number <> 0 Then
  385.             BColor = RGB(255, 255, 255)
  386.             Err.Clear
  387.         End If
  388.         'Setup error handler (make sure lock is removed)
  389.         On Error GoTo FailedLock
  390.         If LockCount& = 0 Then
  391.             'Delete any previous cosmetic children
  392.             grfThis.Graphics.Clear gfCosmetic
  393.             
  394. Dim dd#, ddOld#
  395. Dim TypeHOld As String, ViewHOld As String
  396.                 dd = grfThis.Properties("DiameterH")
  397.                 ddOld = grfThis.Properties("DiameterOldH")
  398.                 
  399.                 TypeH = grfThis.Properties("HType")
  400.                 TypeHOld = grfThis.Properties("HTypeOld")
  401.                 
  402.                 ViewH = grfThis.Properties("HoleView")
  403.                 ViewHOld = grfThis.Properties("HoleViewOld")
  404. Dim x0Old#, y0Old#, x1Old#, y1Old#, x2Old#, y2Old#
  405.                 x0Old = grfThis.Properties("x0OldH")
  406.                 y0Old = grfThis.Properties("y0OldH")
  407.                 x1Old = grfThis.Properties("x1OldH")
  408.                 y1Old = grfThis.Properties("y1OldH")
  409.                 x2Old = grfThis.Properties("x2OldH")
  410.                 y2Old = grfThis.Properties("y2OldH")
  411.                 
  412. '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  413. Dim Salp#, Calp#, L#
  414. Dim X00#, Y00#, X01#, Y01#, X02#, Y02#
  415. Dim LenProp#, LenOld#
  416.         LenProp = grfThis.Properties("LengthH")
  417.         LenOld = grfThis.Properties("LengthOldH")
  418. Dim LenPropThread#, LenThreadOld#
  419. Dim LThread#
  420.  
  421.         LenPropThread = grfThis.Properties("LengthThreadH")
  422.         LThread = LenPropThread
  423.         LenThreadOld = grfThis.Properties("LengthThreadOldH")
  424.  
  425.         With grfThis.Vertices
  426.             X00 = .Item(0).X
  427.             Y00 = .Item(0).Y
  428.             X01 = .Item(1).X
  429.             Y01 = .Item(1).Y
  430.             X02 = .Item(2).X
  431.             Y02 = .Item(2).Y
  432.             L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00))
  433.             If Abs(L) < 0.001 Then
  434.                 X00 = x0Old
  435.                 Y00 = y0Old
  436.                 X01 = x1Old
  437.                 Y01 = y1Old
  438.                 X02 = x2Old
  439.                 Y02 = y2Old
  440.                 L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00))
  441.                 .Item(0).X = X00
  442.                 .Item(0).Y = Y00
  443.                 .Item(1).X = X01
  444.                 .Item(1).Y = Y01
  445.                 .Item(2).X = X02
  446.                 .Item(2).Y = Y02
  447.             End If
  448.             Salp = (Y01 - Y00) / L
  449.             Calp = (X01 - X00) / L
  450.         End With
  451.         
  452. ' If there are changes in Property's Page
  453.         If Abs(dd - ddOld) > 0.001 Or Abs(LenProp - LenOld) > 0.001 Or Abs(LenPropThread - LenThreadOld) > 0.001 Or TypeH <> TypeHOld Or ViewH <> ViewHOld Then
  454.             If ViewH = "FrontSection" And (ViewHOld = "Front" Or ViewHOld = "Top") Then
  455. Dim Calp2#, Salp2#
  456.                 Calp2 = Calp
  457.                 Salp2 = Salp
  458.                 Calp = Salp2
  459.                 Salp = -Calp2
  460.                 X01 = X00 + LenProp * Calp
  461.                 Y01 = Y00 + LenProp * Salp
  462.                 With grfThis.Vertices
  463.                     .Item(1).X = X01
  464.                     .Item(1).Y = Y01
  465.                     L = LenProp
  466.                 End With
  467.                 X02 = X00 + (X01 - X00) * LenPropThread / LenProp
  468.                 Y02 = Y00 + (Y01 - Y00) * LenPropThread / LenProp
  469.                 With grfThis.Vertices
  470.                     .Item(2).X = X02
  471.                     .Item(2).Y = Y02
  472.                 End With
  473.             End If
  474.             If Abs(LenProp - LenOld) > 0.001 And ViewH = ViewHOld Then
  475.                 X01 = X00 + LenProp * Calp
  476.                 Y01 = Y00 + LenProp * Salp
  477.                 With grfThis.Vertices
  478.                     .Item(1).X = X01
  479.                     .Item(1).Y = Y01
  480.                     L = LenProp
  481.                 End With
  482.             End If
  483.             If Abs(LenPropThread - LenThreadOld) > 0.001 And ViewH = ViewHOld Then
  484.                 If LenPropThread > LenProp Then
  485.                     grfThis.Properties("LengthThreadH") = CDbl(Format(LenProp, "###0.00"))
  486.                     LenPropThread = LenProp
  487.                     LThread = LenPropThread
  488.                 End If
  489.                 X02 = X00 + (X01 - X00) * LenPropThread / LenProp
  490.                 Y02 = Y00 + (Y01 - Y00) * LenPropThread / LenProp
  491.                 With grfThis.Vertices
  492.                     .Item(2).X = X02
  493.                     .Item(2).Y = Y02
  494.                 End With
  495.             End If
  496.             GoTo LL
  497.         End If
  498.         
  499. ' If change location of the at least one base vertex
  500.         If Abs(X00 - x0Old) > 0.001 Or Abs(Y00 - y0Old) > 0.001 Or Abs(X01 - x1Old) > 0.001 Or Abs(Y01 - y1Old) > 0.001 Or Abs(X02 - x2Old) > 0.001 Or Abs(Y02 - y2Old) > 0.001 Then
  501.             If ViewH = "Front" Or ViewH = "Top" Then GoTo LL
  502.             If Abs(X00 - x0Old) > 0.001 Or Abs(Y00 - y0Old) > 0.001 Or Abs(X01 - x1Old) > 0.001 Or Abs(Y01 - y1Old) > 0.001 Then
  503.                 grfThis.Properties("LengthH") = CDbl(Format(L, "###0.00"))
  504.                 If LThread > L Then
  505.                     LThread = L
  506.                     grfThis.Properties("LengthThreadH") = CDbl(Format(LThread, "###0.00"))
  507.                 End If
  508.                 X02 = X00 + (X01 - X00) * LThread / L
  509.                 Y02 = Y00 + (Y01 - Y00) * LThread / L
  510.                 With grfThis.Vertices
  511.                     .Item(2).X = X02
  512.                     .Item(2).Y = Y02
  513.                 End With
  514.             End If
  515.             If Abs(X00 - x0Old) < 0.001 And Abs(Y00 - y0Old) < 0.001 And Abs(X01 - x1Old) < 0.001 And Abs(Y01 - y1Old) < 0.001 Then
  516.                 If Abs(X02 - x2Old) > 0.001 Or Abs(Y02 - y2Old) > 0.001 Then
  517.  Dim Salp1#, Calp1#
  518.                     Salp1 = (Y01 - Y00) / L
  519.                     Calp1 = (X01 - X00) / L
  520.                     LThread = (Y02 - Y00) * Salp1 + (X02 - X00) * Calp1
  521.                     If LThread > L Then LThread = L
  522.                     If LThread < 0 Then LThread = 0#
  523.                     grfThis.Properties("LengthThreadH") = CDbl(Format(LThread, "###0.00"))
  524.                     X02 = X00 + (X01 - X00) * LThread / L
  525.                     Y02 = Y00 + (Y01 - Y00) * LThread / L
  526.                     With grfThis.Vertices
  527.                         .Item(2).X = X02
  528.                         .Item(2).Y = Y02
  529.                     End With
  530.                 End If
  531.             End If
  532.         End If
  533. LL:
  534. '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  535.             If TypeH = "Hole1" Then Call Hole1(grfThis, dd, L, Salp, Calp, ViewH, ViewHOld, LThread)
  536.             If TypeH = "Hole2" Then Call Hole2(grfThis, dd, L, Salp, Calp, ViewH, ViewHOld, LThread)
  537.             If TypeH = "Hole3" Then Call Hole3(grfThis, dd, L, Salp, Calp, ViewH, ViewHOld, LThread)
  538.             If TypeH = "Hole4" Then Call Hole4(grfThis, dd, L, Salp, Calp, ViewH, ViewHOld, LThread)
  539.             If TypeH = "Hole5" Then Call Hole5(grfThis, dd, L, Salp, Calp, ViewH, ViewHOld, LThread)
  540.             'Add visible child Graphics
  541.         End If
  542.         grfThis.Properties("DiameterOldH") = grfThis.Properties("DiameterH")
  543.         grfThis.Properties("LengthOldH") = grfThis.Properties("LengthH")
  544.         grfThis.Properties("LengthThreadOldH") = grfThis.Properties("LengthThreadH")
  545.         grfThis.Properties("HTypeOld") = TypeH
  546.         grfThis.Properties("HoleViewOld") = ViewH
  547.         grfThis.Properties("x0OldH") = X00
  548.         grfThis.Properties("y0OldH") = Y00
  549.         grfThis.Properties("x1OldH") = X01
  550.         grfThis.Properties("y1OldH") = Y01
  551.         grfThis.Properties("x2OldH") = X02
  552.         grfThis.Properties("y2OldH") = Y02
  553.  
  554.         
  555.         grfThis.RegenUnlock
  556.         Exit Function
  557.  
  558. FailedLock:
  559.         'Remove lock
  560.         grfThis.RegenUnlock
  561.  
  562. Failed:
  563. End Function
  564.  
  565. Public Function Draw(ByVal grfThis As Object, ByVal view As Object, Optional mat As Variant) As Boolean
  566.     'Return True if we did the redraw (no further processing necessary, no children will be drawn).
  567.     'Since this is just a test, we return False to let TurboCAD do the drawing operation.
  568.     Draw = False
  569. End Function
  570. Private Function Angle(sinb As Double, cosb As Double) As Double
  571.  
  572.         If Abs(cosb) < 0.0001 Then
  573.             If sinb > 0 Then
  574.                 Angle = Pi / 2
  575.             Else
  576.                 Angle = 3 * Pi / 2
  577.             End If
  578.         Else
  579.             If sinb >= 0 And cosb > 0 Then Angle = Atn(sinb / cosb)
  580.             If sinb >= 0 And cosb < 0 Then Angle = Pi + Atn(sinb / cosb)
  581.             If sinb < 0 And cosb < 0 Then Angle = Pi + Atn(sinb / cosb)
  582.             If sinb < 0 And cosb > 0 Then Angle = 2 * Pi + Atn(sinb / cosb)
  583.         End If
  584. End Function
  585.  
  586. Private Sub Hole1(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, ScrewView As String, ScrewViewOld As String, LThread As Double)
  587.  
  588. Dim X00#, Y00#, X01#, Y01#
  589.         With Gr.Vertices
  590.             X00 = .Item(0).X
  591.             Y00 = .Item(0).Y
  592.             X01 = .Item(1).X
  593.             Y01 = .Item(1).Y
  594.             .Item(2).X = X01
  595.             .Item(2).Y = Y01
  596.             .Item(2).Selectable = False
  597.             .Item(2).Editable = False
  598.         End With
  599. Dim del#
  600.         del = 0.1 * dd
  601.         
  602. Dim X0(8)
  603. Dim Y0(8)
  604. Dim X(8)
  605. Dim Y(8)
  606.         X0(1) = 0#
  607.         Y0(1) = dd / 2# + del
  608.           
  609.         X0(2) = X0(1)
  610.         Y0(2) = -Y0(1)
  611.           
  612.         X0(3) = del
  613.         Y0(3) = dd / 2#
  614.           
  615.         X0(4) = X0(3)
  616.         Y0(4) = -Y0(3)
  617.           
  618.         X0(5) = L - del
  619.         Y0(5) = dd / 2#
  620.           
  621.         X0(6) = X0(5)
  622.         Y0(6) = -Y0(5)
  623.           
  624.         X0(7) = L
  625.         Y0(7) = dd / 2 + del
  626.           
  627.         X0(8) = X0(7)
  628.         Y0(8) = -Y0(7)
  629.           
  630.         
  631. Dim i%
  632.         For i = 1 To 8
  633.              X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
  634.              Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
  635.         Next i
  636. Dim GrChild As Graphic
  637.             'Add child Graphics
  638. ' ##########################################################################
  639. ' ##########################################################################
  640.         If ScrewView = "FrontSection" Then
  641.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  642.             With GrChild.Vertices
  643.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  644.                 .Add X(3), Y(3), 0, True, True, False, False, False, False
  645.                 .Add X(5), Y(5), 0, True, True, False, False, False, False
  646.                 .Add X(7), Y(7), 0, True, True, False, False, False, False
  647.                 .Add X(8), Y(8), 0, True, True, False, False, False, False
  648.                 .Add X(6), Y(6), 0, True, True, False, False, False, False
  649.                 .Add X(4), Y(4), 0, True, True, False, False, False, False
  650.                 .Add X(2), Y(2), 0, True, True, False, False, False, False
  651.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  652.             End With
  653.             GrChild.Cosmetic = True
  654.             GrChild.Closed = True
  655.             GrChild.Properties("PenWidth") = 0.02
  656.             GrChild.Properties("PenColor") = PColor
  657.             GrChild.Properties("BrushStyle") = "Solid"
  658.             GrChild.Properties("BrushColor") = BColor
  659.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  660.             With GrChild.Vertices
  661.                 .Add X(3), Y(3), 0, True, True, False, False, False, False
  662.                 .Add X(4), Y(4), 0, True, True, False, False, False, False
  663.                 .Add X(5), Y(5), 0, False, True, False, False, False, False
  664.                 .Add X(6), Y(6), 0, True, True, False, False, False, False
  665.             End With
  666.             GrChild.Cosmetic = True
  667.             GrChild.Properties("PenWidth") = 0.02
  668.             GrChild.Properties("PenColor") = PColor
  669.         
  670.         End If
  671. End Sub
  672.  
  673.  
  674.  
  675. Private Sub Hole2(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, ScrewView As String, ScrewViewOld As String, LThread As Double)
  676.  
  677. Dim X00#, Y00#, X01#, Y01#
  678.         With Gr.Vertices
  679.             X00 = .Item(0).X
  680.             Y00 = .Item(0).Y
  681.             X01 = .Item(1).X
  682.             Y01 = .Item(1).Y
  683.             .Item(2).X = X01
  684.             .Item(2).Y = Y01
  685.             .Item(2).Selectable = False
  686.             .Item(2).Editable = False
  687.         End With
  688. Dim del#
  689.         del = 0.1 * dd
  690.         
  691. Dim X0(6)
  692. Dim Y0(6)
  693. Dim X(6)
  694. Dim Y(6)
  695.        
  696.         X0(1) = 0#
  697.         Y0(1) = dd / 2# + del
  698.           
  699.         X0(2) = X0(1)
  700.         Y0(2) = -Y0(1)
  701.           
  702.         X0(3) = del
  703.         Y0(3) = dd / 2#
  704.           
  705.         X0(4) = X0(3)
  706.         Y0(4) = -Y0(3)
  707.           
  708.         X0(5) = L
  709.         Y0(5) = dd / 2#
  710.           
  711.         X0(6) = X0(5)
  712.         Y0(6) = -Y0(5)
  713.           
  714.         
  715. Dim i%
  716.         For i = 1 To 6
  717.              X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
  718.              Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
  719.         Next i
  720. Dim GrChild As Graphic
  721.             'Add child Graphics
  722. ' ##########################################################################
  723. ' ##########################################################################
  724.         If ScrewView = "FrontSection" Then
  725.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  726.             With GrChild.Vertices
  727.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  728.                 .Add X(3), Y(3), 0, True, True, False, False, False, False
  729.                 .Add X(5), Y(5), 0, True, True, False, False, False, False
  730.                 .Add X(6), Y(6), 0, True, True, False, False, False, False
  731.                 .Add X(4), Y(4), 0, True, True, False, False, False, False
  732.                 .Add X(2), Y(2), 0, True, True, False, False, False, False
  733.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  734.             End With
  735.             GrChild.Cosmetic = True
  736.             GrChild.Closed = True
  737.             GrChild.Properties("PenWidth") = 0.02
  738.             GrChild.Properties("PenColor") = PColor
  739.             GrChild.Properties("BrushStyle") = "Solid"
  740.             GrChild.Properties("BrushColor") = BColor
  741.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  742.             With GrChild.Vertices
  743.                 .Add X(3), Y(3), 0, True, True, False, False, False, False
  744.                 .Add X(4), Y(4), 0, True, True, False, False, False, False
  745.             End With
  746.             GrChild.Cosmetic = True
  747.             GrChild.Properties("PenWidth") = 0.02
  748.             GrChild.Properties("PenColor") = PColor
  749.         
  750.         End If
  751.  
  752. End Sub
  753.  
  754.  
  755. Private Sub Hole3(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, ScrewView As String, ScrewViewOld As String, LThread As Double)
  756.  
  757. Dim X00#, Y00#, X01#, Y01#
  758.         With Gr.Vertices
  759.             X00 = .Item(0).X
  760.             Y00 = .Item(0).Y
  761.             X01 = .Item(1).X
  762.             Y01 = .Item(1).Y
  763.             .Item(2).Selectable = True
  764.             .Item(2).Editable = True
  765.         End With
  766. Dim del#
  767.         del = 0.1 * dd
  768.         
  769. Dim X0(8)
  770. Dim Y0(8)
  771. Dim X(8)
  772. Dim Y(8)
  773.         X0(1) = 0#
  774.         Y0(1) = dd / 2#
  775.           
  776.         X0(2) = X0(1)
  777.         Y0(2) = -Y0(1)
  778.           
  779.         X0(3) = del
  780.         Y0(3) = dd / 2# - del
  781.           
  782.         X0(4) = X0(3)
  783.         Y0(4) = -Y0(3)
  784.           
  785.         X0(5) = L
  786.         Y0(5) = dd / 2# - del
  787.           
  788.         X0(6) = X0(5)
  789.         Y0(6) = -Y0(5)
  790.           
  791.     '-------------------------------
  792.         If LThread > 0 Then
  793.             If LThread > L Then
  794.                 LThread = L
  795.                 Gr.Properties("LengthThread") = L
  796.             End If
  797.             X0(7) = LThread
  798.         Else
  799.             X0(7) = 0#
  800.         End If
  801.         Y0(7) = dd / 2#
  802.         
  803.         X0(8) = X0(7)
  804.         Y0(8) = -Y0(7)
  805.    
  806.         
  807. Dim i%
  808.         For i = 1 To 8
  809.              X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
  810.              Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
  811.         Next i
  812. Dim GrChild As Graphic
  813.             'Add child Graphics
  814. ' ##########################################################################
  815. ' ##########################################################################
  816.         If ScrewView = "FrontSection" Then
  817.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  818.             With GrChild.Vertices
  819.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  820.                 .Add X(3), Y(3), 0, True, True, False, False, False, False
  821.                 .Add X(5), Y(5), 0, True, True, False, False, False, False
  822.                 .Add X(6), Y(6), 0, True, True, False, False, False, False
  823.                 .Add X(4), Y(4), 0, True, True, False, False, False, False
  824.                 .Add X(2), Y(2), 0, True, True, False, False, False, False
  825.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  826.             End With
  827.             GrChild.Cosmetic = True
  828.             GrChild.Closed = True
  829.             GrChild.Properties("PenWidth") = 0.02
  830.             GrChild.Properties("PenColor") = PColor
  831.             GrChild.Properties("BrushStyle") = "Solid"
  832.             GrChild.Properties("BrushColor") = BColor
  833.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  834.             With GrChild.Vertices
  835.                 .Add X(3), Y(3), 0, True, True, False, False, False, False
  836.                 .Add X(4), Y(4), 0, True, True, False, False, False, False
  837.             End With
  838.             GrChild.Cosmetic = True
  839.             GrChild.Properties("PenWidth") = 0.02
  840.             GrChild.Properties("PenColor") = PColor
  841.         'Threading
  842.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  843.             With GrChild.Vertices
  844.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  845.                 .Add X(7), Y(7), 0, True, True, False, False, False, False
  846.                 .Add X(8), Y(8), 0, True, True, False, False, False, False
  847.                 .Add X(2), Y(2), 0, True, True, False, False, False, False
  848.             End With
  849.             GrChild.Cosmetic = True
  850.             GrChild.Properties("PenColor") = PColor
  851.         
  852.         End If
  853.  
  854. End Sub
  855.  
  856.  
  857.  
  858.  
  859. Private Sub Hole4(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, ScrewView As String, ScrewViewOld As String, LThread As Double)
  860.  
  861. Dim X00#, Y00#, X01#, Y01#
  862.         With Gr.Vertices
  863.             X00 = .Item(0).X
  864.             Y00 = .Item(0).Y
  865.             X01 = .Item(1).X
  866.             Y01 = .Item(1).Y
  867.             .Item(2).Selectable = True
  868.             .Item(2).Editable = True
  869.         End With
  870. Dim del#
  871.         del = 0.1 * dd
  872.         
  873. Dim X0(9)
  874. Dim Y0(9)
  875. Dim X(9)
  876. Dim Y(9)
  877.         X0(1) = 0#
  878.         Y0(1) = dd / 2#
  879.           
  880.         X0(2) = X0(1)
  881.         Y0(2) = -Y0(1)
  882.           
  883.         X0(3) = del
  884.         Y0(3) = dd / 2# - del
  885.           
  886.         X0(4) = X0(3)
  887.         Y0(4) = -Y0(3)
  888.           
  889.         X0(5) = L
  890.         Y0(5) = dd / 2# - del
  891.           
  892.         X0(6) = X0(5)
  893.         Y0(6) = -Y0(5)
  894.           
  895.         X0(7) = L + dd / 2# * Tan(Pi / 6)
  896.         Y0(7) = 0#
  897.     '-------------------------------
  898.         If LThread > 0 Then
  899.             If LThread > L Then
  900.                 LThread = L
  901.                 Gr.Properties("LengthThread") = L
  902.             End If
  903.             X0(8) = LThread
  904.         Else
  905.             X0(8) = 0#
  906.         End If
  907.         Y0(8) = dd / 2#
  908.         
  909.         X0(9) = X0(8)
  910.         Y0(9) = -Y0(8)
  911.    
  912.         
  913. Dim i%
  914.         For i = 1 To 9
  915.              X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
  916.              Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
  917.         Next i
  918. Dim GrChild As Graphic
  919.             'Add child Graphics
  920. ' ##########################################################################
  921. ' ##########################################################################
  922.         If ScrewView = "FrontSection" Then
  923.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  924.             With GrChild.Vertices
  925.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  926.                 .Add X(3), Y(3), 0, True, True, False, False, False, False
  927.                 .Add X(5), Y(5), 0, True, True, False, False, False, False
  928.                 .Add X(7), Y(7), 0, True, True, False, False, False, False
  929.                 .Add X(6), Y(6), 0, True, True, False, False, False, False
  930.                 .Add X(4), Y(4), 0, True, True, False, False, False, False
  931.                 .Add X(2), Y(2), 0, True, True, False, False, False, False
  932.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  933.             End With
  934.             GrChild.Cosmetic = True
  935.             GrChild.Closed = True
  936.             GrChild.Properties("PenWidth") = 0.02
  937.             GrChild.Properties("PenColor") = PColor
  938.             GrChild.Properties("BrushStyle") = "Solid"
  939.             GrChild.Properties("BrushColor") = BColor
  940.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  941.             With GrChild.Vertices
  942.                 .Add X(3), Y(3), 0, True, True, False, False, False, False
  943.                 .Add X(4), Y(4), 0, True, True, False, False, False, False
  944.                 .Add X(5), Y(5), 0, False, True, False, False, False, False
  945.                 .Add X(6), Y(6), 0, True, True, False, False, False, False
  946.             End With
  947.             GrChild.Cosmetic = True
  948.             GrChild.Properties("PenWidth") = 0.02
  949.             GrChild.Properties("PenColor") = PColor
  950.         'Threading
  951.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  952.             With GrChild.Vertices
  953.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  954.                 .Add X(8), Y(8), 0, True, True, False, False, False, False
  955.                 .Add X(9), Y(9), 0, True, True, False, False, False, False
  956.                 .Add X(2), Y(2), 0, True, True, False, False, False, False
  957.             End With
  958.             GrChild.Cosmetic = True
  959.             GrChild.Properties("PenColor") = PColor
  960.         
  961.         End If
  962.  
  963. End Sub
  964.  
  965.  
  966.  
  967. Private Sub Hole5(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, ScrewView As String, ScrewViewOld As String, LThread As Double)
  968.  
  969. Dim X00#, Y00#, X01#, Y01#
  970.         With Gr.Vertices
  971.             X00 = .Item(0).X
  972.             Y00 = .Item(0).Y
  973.             X01 = .Item(1).X
  974.             Y01 = .Item(1).Y
  975.             .Item(2).Selectable = True
  976.             .Item(2).Editable = True
  977.         End With
  978. Dim del#
  979.         del = 0.1 * dd
  980.         
  981. Dim X0(9)
  982. Dim Y0(9)
  983. Dim X(9)
  984. Dim Y(9)
  985.         X0(1) = 0#
  986.         Y0(1) = dd / 2#
  987.           
  988.         X0(2) = X0(1)
  989.         Y0(2) = -Y0(1)
  990.           
  991.         X0(3) = 0#
  992.         Y0(3) = dd / 2# - del
  993.           
  994.         X0(4) = X0(3)
  995.         Y0(4) = -Y0(3)
  996.           
  997.         X0(5) = L
  998.         Y0(5) = dd / 2# - del
  999.           
  1000.         X0(6) = X0(5)
  1001.         Y0(6) = -Y0(5)
  1002.           
  1003.         X0(7) = L + dd / 2# * Tan(Pi / 6)
  1004.         Y0(7) = 0#
  1005.     '-------------------------------
  1006.         If LThread > 0 Then
  1007.             If LThread > L Then
  1008.                 LThread = L
  1009.                 Gr.Properties("LengthThread") = L
  1010.             End If
  1011.             X0(8) = LThread
  1012.         Else
  1013.             X0(8) = 0#
  1014.         End If
  1015.         Y0(8) = dd / 2#
  1016.         
  1017.         X0(9) = X0(8)
  1018.         Y0(9) = -Y0(8)
  1019.    
  1020.         
  1021. Dim i%
  1022.         For i = 1 To 9
  1023.              X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
  1024.              Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
  1025.         Next i
  1026. Dim GrChild As Graphic
  1027.             'Add child Graphics
  1028. ' ##########################################################################
  1029. ' ##########################################################################
  1030.         If ScrewView = "FrontSection" Then
  1031.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  1032.             With GrChild.Vertices
  1033.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  1034.                 .Add X(3), Y(3), 0, True, True, False, False, False, False
  1035.                 .Add X(5), Y(5), 0, True, True, False, False, False, False
  1036.                 .Add X(7), Y(7), 0, True, True, False, False, False, False
  1037.                 .Add X(6), Y(6), 0, True, True, False, False, False, False
  1038.                 .Add X(4), Y(4), 0, True, True, False, False, False, False
  1039.                 .Add X(2), Y(2), 0, True, True, False, False, False, False
  1040.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  1041.             End With
  1042.             GrChild.Cosmetic = True
  1043.             GrChild.Closed = True
  1044.             GrChild.Properties("PenWidth") = 0.02
  1045.             GrChild.Properties("PenColor") = PColor
  1046.             GrChild.Properties("BrushStyle") = "Solid"
  1047.             GrChild.Properties("BrushColor") = BColor
  1048.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  1049.             With GrChild.Vertices
  1050.                 .Add X(3), Y(3), 0, True, True, False, False, False, False
  1051.                 .Add X(4), Y(4), 0, True, True, False, False, False, False
  1052.                 .Add X(5), Y(5), 0, False, True, False, False, False, False
  1053.                 .Add X(6), Y(6), 0, True, True, False, False, False, False
  1054.             End With
  1055.             GrChild.Cosmetic = True
  1056.             GrChild.Properties("PenWidth") = 0.02
  1057.             GrChild.Properties("PenColor") = PColor
  1058.         'Threading
  1059.             Set GrChild = Gr.Graphics.Add(gkGraphic)
  1060.             With GrChild.Vertices
  1061.                 .Add X(1), Y(1), 0, True, True, False, False, False, False
  1062.                 .Add X(8), Y(8), 0, True, True, False, False, False, False
  1063.                 .Add X(9), Y(9), 0, True, True, False, False, False, False
  1064.                 .Add X(2), Y(2), 0, True, True, False, False, False, False
  1065.             End With
  1066.             GrChild.Cosmetic = True
  1067.             GrChild.Properties("PenColor") = PColor
  1068.         
  1069.         End If
  1070.  
  1071. End Sub
  1072.  
  1073.  
  1074.